package com.book.bookprojectapplication.write.fragment;


import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.book.bookprojectapplication.R;
import com.book.bookprojectapplication.write.activity.WriteDecorateActivity;

public class WriteDecoStrFragment extends Fragment {
	TextView writeDecoStrSans=null,
			writeDecoStrMilky=null,
			writeDecoStrNgo=null,
			writeDecoStrNpen=null,
			writeDecoStrNson=null,
			writeDecoStrFont1=null,
			writeDecoStrFont2=null,
			writeDecoStrFont3=null,
			writeDecoStrFont4=null,
			writeDecoStrFont5=null;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		System.out.println("Deco Str onCreateView() start");
		View v = inflater.inflate(R.layout.fragmentwritedecostr, container,
				false);
		
		
		
		
		writeDecoStrSans = (TextView) v
				.findViewById(R.id.writedecostrsans);
		writeDecoStrMilky = (TextView) v
				.findViewById(R.id.writedecostrmilky);
		writeDecoStrNgo = (TextView) v
				.findViewById(R.id.writedecostrngo);
		writeDecoStrNpen = (TextView) v
				.findViewById(R.id.writedecostrnpen);
		writeDecoStrNson = (TextView) v
				.findViewById(R.id.writedecostrnson);

		System.out.println("setFontStr start");
		setFontStr(writeDecoStrSans, "font/DroidSans.ttf");
		setFontStr(writeDecoStrMilky, "font/MILKYWAY.ttf");
		setFontStr(writeDecoStrNgo, "font/NanumGothic.ttf");
		setFontStr(writeDecoStrNpen, "font/NanumPen.ttf");
		setFontStr(writeDecoStrNson, "font/NanumSon.ttf");
		System.out.println("setFontStr end");

		writeDecoStrFont1 = (TextView) v
				.findViewById(R.id.writedecostrfont1);
		writeDecoStrFont2 = (TextView) v
				.findViewById(R.id.writedecostrfont2);
		writeDecoStrFont3 = (TextView) v
				.findViewById(R.id.writedecostrfont3);
		writeDecoStrFont4 = (TextView) v
				.findViewById(R.id.writedecostrfont4);
		writeDecoStrFont5 = (TextView) v
				.findViewById(R.id.writedecostrfont5);

		writeDecoStrSans.setOnClickListener(writeDecoStrListener);
		writeDecoStrMilky.setOnClickListener(writeDecoStrListener);
		writeDecoStrNgo.setOnClickListener(writeDecoStrListener);
		writeDecoStrNpen.setOnClickListener(writeDecoStrListener);
		writeDecoStrNson.setOnClickListener(writeDecoStrListener);

		writeDecoStrFont1.setOnClickListener(writeDecoStrFontListener);
		writeDecoStrFont2.setOnClickListener(writeDecoStrFontListener);
		writeDecoStrFont3.setOnClickListener(writeDecoStrFontListener);
		writeDecoStrFont4.setOnClickListener(writeDecoStrFontListener);
		writeDecoStrFont5.setOnClickListener(writeDecoStrFontListener);
		

		return v;
	}

	OnClickListener writeDecoStrListener = new OnClickListener() {
		Typeface tf = null;
		
		@Override
		public void onClick(View v) {
			System.out.println("onclick start");	
			
			switch (v.getId()) {
			case R.id.writedecostrsans:
				tf = Typeface.createFromAsset(getActivity().getAssets(),
						"font/DroidSans.ttf");			
				WriteDecorateActivity.setStrEdit(tf);
				break;
			case R.id.writedecostrmilky:
				tf = Typeface.createFromAsset(getActivity().getAssets(),
						"font/MILKYWAY.ttf");
				
			
				WriteDecorateActivity.setStrEdit(tf);
				break;
			case R.id.writedecostrngo:
				tf = Typeface.createFromAsset(getActivity().getAssets(),
						"font/NanumGothic.ttf");
				
				
				WriteDecorateActivity.setStrEdit(tf);
				break;
			case R.id.writedecostrnson:
				tf = Typeface.createFromAsset(getActivity().getAssets(),
						"font/NanumSon.ttf");
				
				
				WriteDecorateActivity.setStrEdit(tf);
				break;
			case R.id.writedecostrnpen:
				tf = Typeface.createFromAsset(getActivity().getAssets(),
						"font/NanumPen.ttf");
				
				
				
				WriteDecorateActivity.setStrEdit(tf);
				break;
			}			
		}
	};
	OnClickListener writeDecoStrFontListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.writedecostrfont1:
				WriteDecorateActivity.setFontSizeEdit(
						TypedValue.COMPLEX_UNIT_PX, 10);
				break;
			case R.id.writedecostrfont2:
				WriteDecorateActivity.setFontSizeEdit(
						TypedValue.COMPLEX_UNIT_PX, 12);
				break;
			case R.id.writedecostrfont3:
				WriteDecorateActivity.setFontSizeEdit(
						TypedValue.COMPLEX_UNIT_PX, 14);
				break;
			case R.id.writedecostrfont4:
				WriteDecorateActivity.setFontSizeEdit(
						TypedValue.COMPLEX_UNIT_PX, 16);
				break;
			case R.id.writedecostrfont5:
				WriteDecorateActivity.setFontSizeEdit(
						TypedValue.COMPLEX_UNIT_PX, 18);
				break;
			}

		}
	};

	private void setFontStr(TextView name, String path) {
		Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), path);
		name.setTypeface(tf);
	}
}
